﻿using System.Text.Json.Serialization;
using System.Text.Json;

namespace Sirius.Data
{
    public static class PackManager
    {
        public static string CreateAuthPack(string BotId,string Token,int intent)
        {
            return JsonSerializer.Serialize(new AuthPack(BotId, Token,intent, null));
        }
        public static string CreateHeart_BeatPack(int d)
        {
            return JsonSerializer.Serialize(new Heart_Beat(d));
        }
        
        public static string CreateResume(string Token,String Session_id,int Seq)
        {
            return JsonSerializer.Serialize(new Resume(Token, Session_id, Seq));
        }

    }
    public class DataPackBase
    {
        public DataPackBase(opCode opCode)
        {
            this.OpCode = (int)opCode;
        }

        [JsonPropertyName("op")]
        public int OpCode { get; set; }

        [JsonPropertyName("d")]
        public Object Data{ get; set; }

}

    public class AuthPack:DataPackBase
    {
        public AuthPack(string BotId,string Token,long intents,Object? properties):base(opCode.IDENTIFY)
        {
            data.Token = $"{BotId}.{Token}";
            data.Intents = intents;
            data.Properties = properties;
            Data = data;
        }
        [JsonPropertyName("d")]
        public D data = new();
        public class D
        {
            [JsonPropertyName("token")]
            public string Token { get; set; }

            [JsonPropertyName("intents")]
            public long Intents { get; set; }

            [JsonPropertyName("shard")]
            public int[] Shard = new[] { 0, 1 };

            [JsonPropertyName("properties")]
            public object? Properties { get; set; }
        }
    }

    public class Heart_Beat:DataPackBase
    {
        public Heart_Beat(int d):base(opCode.HEARTBEAT)
        {
            Data = d;
        }
    }

    public class Resume:DataPackBase
    {
        public Resume(string Token,string Session_Id,int seq):base(opCode.RESUME)
        {
            data.Token=Token;
            data.Session_Id = Session_Id;
            data.Seq = seq;
            Data = data;
        }
        public D data=new();
        public class D
        {
            [JsonPropertyName("token")]
            public string Token { get; set; }

            [JsonPropertyName("session_id")]
            public string Session_Id { get; set; }

            [JsonPropertyName("seq")]
            public int Seq { get; set; }
        }
       
    }
}
